<template>
  <div class="app-container">
    <el-input
      class="ipt"
      @change="sear"
      v-model="input"
      prefix-icon="el-icon-search"
      placeholder="请输入内容"
    ></el-input>
    <el-drawer
      title="表单"
      :visible.sync="drawer"
      :direction="direction"
      :before-close="handleClose"
      size="45%"
    >
      <el-form
        :model="form"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="标题" prop="name">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="单价" prop="price">
          <el-input v-model="form.price"></el-input>
        </el-form-item>
        <el-form-item label="数量" prop="num">
          <el-input v-model="form.num"></el-input>
        </el-form-item>
        <el-form-item label="状态" style="margin-right:50px" prop="author">
          <el-select v-model="form.zhuangtai" placeholder="请选择活动区域">
            <el-option label="未购买" :value="0"></el-option>
            <el-option label="已购买" :value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="qdBtn">确定</el-button>
          <el-button @click="drawer=false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-drawer>
    <el-table
      :data="list"
      border
      style="width: 100%;margin:20px 0;"
      :default-sort="{prop: 'date', order: 'descending'}"
      @sort-change="changeFn"
    >
      <el-table-column prop="name" label="商品名称" width="250"></el-table-column>
      <el-table-column prop="dingdan" label="订单号" width="200"></el-table-column>
      <el-table-column prop="price" sortable label="价格" width="200"></el-table-column>
      <el-table-column prop="num" label="数量" width="300"></el-table-column>
      <el-table-column prop="cutoffTime" sortable label="结账时间" width="200"></el-table-column>
      <el-table-column prop="zhuangtai" sortable label="状态" width="200"></el-table-column>
      <el-table-column fixed="right" label="操作" width="150">
        <template slot-scope="scope">
          <!-- <template> -->
          <el-button type="text" @click="xgData(scope.row)" size="small">编辑</el-button>
          <el-button type="text" @click="delData(scope.row)" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page.currentPage"
      :page-sizes="[1, 2, 3, 5,10]"
      :page-size="page.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    ></el-pagination>
  </div>
</template>

<script>
import { mapActions, mapState, mapMutations } from "vuex";
export default {
  data() {
    return {
      // sear,
      input: "",
      direction: "rtl",
      drawer: false,
      form: {},
      rules: {
        title: [{ required: true, message: "请输入表头", trigger: "blur" }],
        author: [{ required: true, message: "请输入发布人", trigger: "blur" }],
        cid: [{ required: true, message: "请选择类别", trigger: "change" }],
        time: [
          { required: true, message: "请选择阅读时间", trigger: "change" }
        ],
        content: [{ required: true, message: "请输入内容", trigger: "blur" }]
      }
    };
  },
  methods: {
    ...mapActions("jiezhang", [
      "getData",
      "setCurrentPage",
      "setPageSize",
      "DelteData",
      "UpData",
      "search"
    ]),
    sear() {
      if (this.input == "") return;
      this.setCurrentPage(1);
      this.search(this.input);
    },
    handleClose() {},
    changeFn() {},
    handleCurrentChange(e) {
      this.setCurrentPage(e);
    },
    handleSizeChange(e) {
      this.setPageSize(e);
    },
    //删除
    delData(val) {
      this.DelteData(val.id);
    },
    //修改
    xgData(val) {
      let obj = JSON.parse(JSON.stringify(val));
      this.form = obj;
      this.drawer = true;
    },
    //确定提交
    qdBtn() {
      this.UpData(this.form);
      this.form = {};
      this.drawer = false;
    }
  },
  computed: {
    ...mapState("jiezhang", ["list", "total", "page"])
  },
  mounted() {
    this.getData();
  }
};
</script>

<style scoped>
</style>